package com.srd.phone.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shengrongdai.srd.R;
import com.srd.phone.bean.MessageBean;
import com.srd.phone.utils.views.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class MessAdapter extends BaseAdapter {

    private Context context;
    private List<MessageBean> list = new ArrayList<>(10);

    public MessAdapter(Context context, List<MessageBean> list0) {
        this.context = context;
        list = list0;
    }

    public void setData(List<MessageBean> list0) {
        list = list0;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public MessageBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        ViewHolder viewHolder =  ViewHolder.get(context, view, parent, R.layout.item_message_list, position);
        final MessageBean item = getItem(position);

        TextView tv_title_name = viewHolder.getView(R.id.tv_title_name);
        TextView tv_info = viewHolder.getView(R.id.tv_info);
        TextView tv_date = viewHolder.getView(R.id.tv_date);

        if(item.state == 84){  // 已读
            tv_title_name.setTextColor(context.getResources().getColor(R.color.gray));
            tv_info.setTextColor(context.getResources().getColor(R.color.gray));
            tv_date.setTextColor(context.getResources().getColor(R.color.gray));
        }else{
            tv_title_name.setTextColor(context.getResources().getColor(R.color.font_color));
            tv_info.setTextColor(context.getResources().getColor(R.color.font_color));
            tv_date.setTextColor(context.getResources().getColor(R.color.font_color));
        }
        tv_title_name.setText(item.title);
        tv_info.setText(item.content);
        tv_date.setText(item.ctime);

        return viewHolder.getConvertView();
    }

}
